package com.daxia.bumall.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * ProductCategory
 */
@Entity
@Table(name = "productcategory") 
public class ProductCategory extends BaseModel {
	/**
	 * id
	 */
	@Id
	@GeneratedValue
	@Column(name = "id")
    private Long id;
	private Integer level;
	/**
	 * 分类名称
	 */
	@Column(name = "name")
    private String name;
	/**
	 * 状态，0正常，1失效
	 */
	@Column(name = "status")
    private Integer status;
	/**
	 * 编码
	 */
	@Column(name = "code")
    private String code;
	/**
	 * 父分类
	 */
	@ManyToOne
	@JoinColumn(name = "parent_category_id")
    private ProductCategory parentCategory;
	
	@OneToMany(mappedBy = "parentCategory")
	//@OrderBy(value  = "level ASC, seq ASC")
	private List<ProductCategory> children = new ArrayList<ProductCategory>();
	
	@OneToMany(mappedBy = "productCategory")
	private List<ProductCategoryTag> tags = new ArrayList<ProductCategoryTag>();
	
	/**
	 * 分类图片
	 */
	@Column(name = "image")
    private String image;
	
	public Long getId() {
    	return id;
    }
	
    public void setId(Long id) {
    	this.id = id;
    }
	
	public String getName() {
    	return name;
    }
	
    public void setName(String name) {
    	this.name = name;
    }
	
	public Integer getStatus() {
    	return status;
    }
	
    public void setStatus(Integer status) {
    	this.status = status;
    }
	
	public String getCode() {
    	return code;
    }
	
    public void setCode(String code) {
    	this.code = code;
    }
	
	public ProductCategory getParentCategory() {
    	return parentCategory;
    }
	
    public void setParentCategory(ProductCategory parentCategory) {
    	this.parentCategory = parentCategory;
    }
	
	public String getImage() {
    	return image;
    }
	
    public void setImage(String image) {
    	this.image = image;
    }

	public List<ProductCategory> getChildren() {
		return children;
	}

	public void setChildren(List<ProductCategory> children) {
		this.children = children;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public List<ProductCategoryTag> getTags() {
		return tags;
	}

	public void setTags(List<ProductCategoryTag> tags) {
		this.tags = tags;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (this == obj) {
			return true;
		}
		if (obj instanceof ProductCategory) {
			ProductCategory p = (ProductCategory) obj;
			if (p.getId() == this.id && p.getName().equals(this.name)) {
				return true;
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return this.id.hashCode() * this.name.hashCode();
	}
	
	
	
}
